Public Class FrmSubRepositories
    Public DOC_CAT_ID As Integer
    Private Sub FrmSubRepositories_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DsTempList.TBL_DOC_CAT' table. You can move, or remove it, as needed.
        'TODO: This line of code loads data into the 'DsTempList.TBL_DOC_SUB_CAT' table. You can move, or remove it, as needed.
        If DOC_CAT_ID = 0 Then
            Me.TBL_DOC_SUB_CATTableAdapter.Fill(Me.DsTempList.TBL_DOC_SUB_CAT)
            Me.TBL_DOC_CATTableAdapter.Fill(Me.DsTempList.TBL_DOC_CAT)
        Else
            Me.TBL_DOC_SUB_CATTableAdapter.FillByCATEGOTY_ID(Me.DsTempList.TBL_DOC_SUB_CAT, DOC_CAT_ID)
            Me.TBL_DOC_CATTableAdapter.FillByDOC_CAT_ID(Me.DsTempList.TBL_DOC_CAT, DOC_CAT_ID)
        End If
        If Me.DsTempList.TBL_DOC_SUB_CAT.Rows.Count = 0 Then
            Me.TBLDOCSUBCATBindingSource.AddNew()
            cboRepository.SelectedValue = DOC_CAT_ID
            Me.btnDelete.Enabled = False
            Me.btnCancel.Enabled = True
            chkActive.Checked = False
        End If
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Me.txtRepositoryName.Text.Trim = "" Then
            MessageBox.Show("Invalid Sub Repository Name", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        If Me.txtRepositoryDesc.Text.Trim = "" Then
            MessageBox.Show("Invalid Sub Repository Description", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        If Me.chkActive.CheckState = CheckState.Indeterminate Then
            Me.chkActive.Checked = True
        End If
        Me.TBLDOCSUBCATBindingSource.EndEdit()
        Me.TBL_DOC_SUB_CATTableAdapter.Update(Me.DsTempList.TBL_DOC_SUB_CAT)
    End Sub

    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        Me.TBLDOCSUBCATBindingSource.AddNew()
        cboRepository.SelectedValue = DOC_CAT_ID
        Me.btnDelete.Enabled = False
        Me.btnCancel.Enabled = True
        chkActive.Checked = False
    End Sub

    Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
        If DataGridView1.SelectedRows.Count > 0 Then
            Me.btnDelete.Enabled = True
            Me.btnCancel.Enabled = False
        End If
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If MessageBox.Show("Are You Want Delete Selected Category?", "Virtual Desk", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Dim cdata As New Data
            cdata.DS_Read("DELETE TBL_DOC_SUB_CAT WHERE DOC_SUB_CAT_ID=" & DataGridView1.SelectedCells.Item(0).Value, "DSDELETE")
            If DOC_CAT_ID = 0 Then
                Me.TBL_DOC_SUB_CATTableAdapter.Fill(Me.DsTempList.TBL_DOC_SUB_CAT)
                Me.TBL_DOC_CATTableAdapter.Fill(Me.DsTempList.TBL_DOC_CAT)
            Else
                Me.TBL_DOC_SUB_CATTableAdapter.FillByCATEGOTY_ID(Me.DsTempList.TBL_DOC_SUB_CAT, DOC_CAT_ID)
                Me.TBL_DOC_CATTableAdapter.FillByDOC_CAT_ID(Me.DsTempList.TBL_DOC_CAT, DOC_CAT_ID)
            End If
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.TBLDOCSUBCATBindingSource.CancelEdit()
    End Sub
End Class